home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util4 / 0utils.lha / 0Utils / VolName.data < prev    next >
Text File  |  1995-08-19  |  3KB  |  152 lines

  1.  
  2. #ifdef TPLTER
  3.  
  4. VolName = {
  5.  
  6.     SHORT = {{ get the Volumename of a file }};
  7.  
  8.     DESCRIPTION = {{
  9.     VolName gets a filename and evaluates its
  10.     Volumename.
  11.  
  12.     If VOLUME is selected, we call GetNameFromLock
  13.     and evaluate the Volumename from that string
  14.  
  15.     If DEVICE is selected, we try to get the
  16.     Devicename instead of the Volumename.
  17.  
  18.     DEVICE hides VOLUME.
  19.  
  20.     The resulting string is sent to STDOUT.
  21.  
  22.      RESULT
  23.     the volumename of the file, or empty string
  24.     if information can not be found
  25.     }};
  26.  
  27.     BUGS = {{
  28.     We use 'Lock' to check the file, so an exclusively
  29.     locked or non existant file is not recognized, if
  30.     one of the flags is given.
  31.     }};
  32.  
  33.     EXAMPLES = {{
  34.     (we are assuming You use a unmodified Workbench)
  35.  
  36.     >VolName ENV:Sys
  37.     ENV:
  38.  
  39.     >VolName ENV:Sys VOLUME
  40.     Ram Disk:
  41.  
  42.     >VolName ENV:Sys DEVICE
  43.     RAM:
  44.     }};
  45.  
  46.     HISTORY = {{
  47.     08-02-95 b_noll created
  48.     11-02-95 b_noll enabled 'DEVICE/S', changed 'PHYSICAL' to 'VOLUME'
  49.     20-02-95 b_noll restructured source
  50.     21-02-95 b_noll added version/format-prefix/offset
  51.     20-03-95 b_noll added args diagnostics
  52.     19-08-95 b_noll created .data file
  53.     }};
  54.  
  55.  
  56.     Template = "FILE/A,VOLUME/S,DEVICE/S";
  57.     Arguments = {{
  58.     STRPTR file;
  59.     ULONG  volume;
  60.     ULONG  device;
  61.     }};
  62.  
  63.     version =  "1.3";
  64.  
  65.     body = {{
  66.         APTR        processwin;
  67.         struct Process *process;
  68.         STRPTR        filename = argv->file;
  69.         //UBYTE        buffer[MAXPATHLEN];
  70.         BPTR        out;
  71.  
  72.         out = Output();
  73.  
  74.         if ((process = (struct Process *)FindTask(NULL))) {
  75.         processwin = process->pr_WindowPtr;
  76.         process->pr_WindowPtr = (APTR)-1;
  77.         } /* if */
  78.  
  79.         if (argv->device || argv->volume || !*filename) {
  80.  
  81.         BPTR lock;
  82. //dolock:
  83.  
  84.         if (lock = Lock(filename, SHARED_LOCK)) {
  85.             struct FileLock *fl;
  86.             struct DosList  *dl;
  87.  
  88.             fl = BADDR(lock);
  89.             dl = BADDR(fl->fl_Volume);
  90.  
  91.             if (argv->device) {
  92.             struct MsgPort    *mp;
  93.  
  94.             mp = dl->dol_Task;
  95.  
  96.             dl = LockDosList(LDF_DEVICES|LDF_READ);
  97.             while (dl = NextDosEntry(dl,LDF_DEVICES)) {
  98.                 if (dl->dol_Task == mp) {
  99.                 FPrintf(out, "%b:\n", dl->dol_Name);
  100.                 out = 0;
  101.                 break;
  102.                 } /* if Found */
  103.             } /* while Searching */
  104.             UnLockDosList(LDF_DEVICES|LDF_READ);
  105.             } else {
  106.             FPrintf(out, "%b:\n", dl->dol_Name);
  107.             out = 0;
  108.             } /* if (!)Device */
  109.  
  110.             UnLock (lock);
  111.         } /* if Lock */
  112.         } /* if DoLocking */
  113.  
  114.  
  115.  
  116.         /* ---- Extract the Volumepart */
  117.         if (out) {
  118. #ifdef ALPHA
  119.         UBYTE buffer[MAXPATHLEN];
  120.         if (SplitName(filename, ':', buffer, 0, MAXPATHLEN) != -1) {
  121.             FPrintf(out, "%s:\n", buffer);
  122.             out = 0;
  123. //          } else if (*filename) {
  124. //              filename = "";
  125. //              goto dolock;
  126.         } /* if */
  127. #else
  128.         UBYTE        c, *p;
  129.         for (p = filename; (c = *p) && c != ':'; ++p);
  130.         if (c) {
  131.             *p = 0;
  132.             FPrintf(out, "%s:\n", filename);
  133.             out = 0;
  134.             *p = ':';
  135. //          } else if (*filename) {
  136. //              filename = "";
  137. //              goto dolock;
  138.         } /* if */
  139. #endif
  140.         } /* if */
  141.         //PutStr (":\n");
  142.         retval = out ? RETURN_WARN : RETURN_OK;
  143.  
  144.  
  145.         if (process != NULL) {
  146.         process->pr_WindowPtr = processwin;
  147.         } /* if */
  148.     }};
  149. };
  150. #endif
  151.  
  152.